import {messages} from "share/common";
import React,{Component} from 'react';
import {Button} from 'antd';
import AdvanceTable from 'components/advanced-table';
import DataOfColumns from './data-of-column';
import DataOfSearchForm from './data-of-search-form';
import GeneralViewServer from './authorize-view-server';
import openSlideFrame from "share/openSlideFrame";
import 'styles/financial-management/general-view/general-view.scss'

class AuthorizeView extends Component{

  constructor(props){
    super(props);

    this.columns = DataOfColumns.getGeneralViewColumns();
    this.searchForm = DataOfSearchForm.getGeneralViewSearchForm();
    this.searchParams = {
      page: 0,
      size: 10,
      keyName: '',
      sortType: 'desc',// 'ASC'
    },
    this.state = {
      downloadUrl: '',
      isFail: false,
    }
  }

  createTableOption = () => {
    return {
      key: 'authorizeView',
      tableName: 'authorizeView',
      title: messages('supplier-1.key1')/*我的申请*/,
      service: this.advanceTableServer,
      index: true,
      onRef: this.advanceTableRef,
      rowKey: record => record.id,
      columns: this.columns,
      onChange: this.onSortChange,
      searchForm: this.searchForm,
      footer: <Button onClick={()=>{window.history.go(-1)}}>{messages('common.back')/*返回*/}</Button>,
      bordered: true,
      onRow: (record) => {
        return {
          onClick: () => {
            openSlideFrame.openOtherReport({
              formOID: record.formOID,
              entityOID: record.entityOID,
              status: 'approving',
              approverOID: record.approverOID,
              entry: 'slide',
              slideReadOnly: true
            }, {
              afterClose: value => {
                typeof value === 'boolean' && value && this.tableRef.getList();
              },
            }, this);
          }
        };
      }
    }
  }

  onSortChange = (pagination, filter, sorter) => {
    if (sorter.order) {
      this.searchParams.keyName = sorter.columnKey;
      this.searchParams.sortType = sorter.order === 'ascend' ? 'asc' : 'desc';
      this.tableRef.getList();
    }
  };

  advanceTableRef = (ref) => {
    this.tableRef = ref;
  }

  advanceTableServer = (page, size, searchValues) => {
    this.searchParams = Object.assign({},this.searchParams, {page: page, size: size}, searchValues);
    return GeneralViewServer(this).getGeneralViewData(this.searchParams);
  }

  render(){
    return (
      <div className='general-view-box'>
        <div style={{height: 'calc(100vh - 64px)'}}>
          <AdvanceTable {...this.createTableOption()} />
        </div>
      </div>
    )
  }
}

export default AuthorizeView;
